﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tesla.DataAccess.DataAccessLogic;
using Tesla.Service.DataContracts;
using Tesla.Util.Utilities;
//using Microsoft.Practices.EnterpriseLibrary.Caching;

namespace Tesla.DataAccess.DataAccessLogic.Implementations
{
    public abstract class BaseOperationalDA : BaseDA
    {
        public virtual int? Create(BaseDC contractObject)
        {
            throw new NotImplementedException("Create Not Implemented");
        }

        public virtual int Update(BaseDC contractObject)
        {
            throw new NotImplementedException("Update Not Implemented");
        }

        public virtual int Delete(BaseDC contractObject)
        {
            throw new NotImplementedException("Delete Not Implemented");
        }

        //USED FOR DISPLAY ALL FUNCTIONALITY IN GRID
        //BASICALLY IT PICKS ONLY THE GRID'S 1ST PAGE DATA AND THE TOTAL COUNT
        public virtual IList<BaseDC> DisplayAll(int gridSize, ref int? totalRecordCount)
        {
            throw new NotImplementedException("Display All Not Implemented");
        }

        public virtual IList<BaseDC> SearchByName(string name, int gridSize, ref int? totalRecordCount)
        {
            throw new NotImplementedException("Search By Name Not Implemented");
        }

        public virtual IList<BaseDC> Read(int id)
        {
            throw new NotImplementedException("Read Not Implemented");
        }

        public virtual IList<BaseDC> ReadByRange(int startRecordNo, int endRecordNo, string sortColName, string sortDirection, string searchString)
        {
            throw new NotImplementedException("Read By Range Not Implemented");
        }

        //READS ALL DATA POSSIBLY TO POPULATE LISTBOXES ETC.
        public virtual IList<BaseDC> ReadAll()
        {
            throw new NotImplementedException("Read All Not Implemented");
        }

        //public IList<BaseDC> InvolveCache(params object[] objList)
        //{
        //    ICacheManager cacheManager = CacheFactory.GetCacheManager();
        //    IList<BaseDC> baseDCs = null;

        //    switch (objList.Length)
        //    {
        //        case 1:
        //            baseDCs = cacheManager.Contains(objList[0].ToString()) ? cacheManager.GetData(objList[0].ToString()) as IList<BaseDC> : null;
        //            break;
        //        case 2:
        //            baseDCs = objList[1] as IList<BaseDC>;
        //            cacheManager.Add(objList[0].ToString(), baseDCs);
        //            break;
        //    }
        //    return baseDCs;
        //}
    }

    public static class DAFactory
    {
        public static BaseOperationalDA CreateInstance(int id)
        {
            BaseOperationalDA instance = GenericClassFactory<int, BaseOperationalDA>.CreateInstance(id);
            if (instance == null)
            {
                string typeName = ResolveMapper.ResolveMethod(id);
                Type type = Type.GetType(typeName);
                GenericClassFactory<int, BaseOperationalDA>.Add(id, type);
                instance = GenericClassFactory<int, BaseOperationalDA>.CreateInstance(id);
            }
            return instance;
        }
    }
}
